
PROJECT(osgDraco)
SET(PROJECT_NAME osgDraco)

cmake_minimum_required(VERSION 3.6)
SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules/")
# include(OsgMacroUtils)

# FIND_PACKAGE(Doxygen)
FIND_PACKAGE(OpenGL)
FIND_PACKAGE(openThreads)
FIND_PACKAGE(osg)
FIND_PACKAGE(osgDB)
FIND_PACKAGE(osgUtil)
FIND_PACKAGE(osgGA)
FIND_PACKAGE(osgViewer)
# FIND_PACKAGE(osgText)
# FIND_PACKAGE(osgAnimation)
# FIND_PACKAGE(osgShadow)
# FIND_PACKAGE(osgTerrain)

FIND_PACKAGE(Draco)

SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)


#SET(OUTPUT_BINDIR ${PROJECT_BINARY_DIR}/bin/${CMAKE_SYSTEM_NAME})
SET(OUTPUT_BINDIR ${PROJECT_BINARY_DIR}/bin)
MAKE_DIRECTORY(${OUTPUT_BINDIR})
IF(MSVC AND NOT MSVC_IDE)
    MAKE_DIRECTORY(${OUTPUT_BINDIR}/${OSG_PLUGINS})
ENDIF(MSVC AND NOT MSVC_IDE)

#SET(OUTPUT_LIBDIR ${PROJECT_BINARY_DIR}/lib/${CMAKE_SYSTEM_NAME})
SET(OUTPUT_LIBDIR ${PROJECT_BINARY_DIR}/lib)
MAKE_DIRECTORY(${OUTPUT_LIBDIR})
IF(NOT MSVC OR MSVC_IDE)
    MAKE_DIRECTORY(${OUTPUT_LIBDIR}/${OSG_PLUGINS})
ENDIF(NOT MSVC OR MSVC_IDE)


IF(CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION LESS 5)
    SET(EXECUTABLE_OUTPUT_PATH ${OUTPUT_BINDIR})
    SET(LIBRARY_OUTPUT_PATH    ${OUTPUT_LIBDIR})
ELSE()
    # If CMake >= 2.6.0
    SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_LIBDIR})
    SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_BINDIR})
    IF(WIN32)
        SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_BINDIR})
    ELSE(WIN32)
        SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_LIBDIR})
    ENDIF(WIN32)
ENDIF()


# set postfix
SET(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually d on windows")
SET(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
SET(CMAKE_RELWITHDEBINFO_POSTFIX "rd" CACHE STRING "add a postfix, usually empty on windows")
SET(CMAKE_MINSIZEREL_POSTFIX "s" CACHE STRING "add a postfix, usually empty on windows")

INCLUDE_DIRECTORIES(include ${CMAKE_INCLUDE_PATH})
LINK_DIRECTORIES(${CMAKE_LIBRARY_PATH})


#option
OPTION(BUILD_STATIC_LIBRAY "build static library" OFF)

# Draco requires C++11 support.
include("compiler_flags")
require_cxx_flag_nomsvc("-std=c++11")

#surport c++11
if(CMAKE_COMPILER_IS_GNUCXX)
    add_definitions( -std=c++11 )
endif()


#input NIUBI_SETUP_TARGET_NAME
#input NIUBI_SETUP_SOURCES
#input NIUBI_SETUP_HEADERS
MACRO(NIUBI_SETUP_LIBRARY)

    SET(HEADERS_GROUP "Header Files")
    SOURCE_GROUP( ${HEADERS_GROUP} FILES ${NIUBI_SETUP_HEADERS})

    # NIUBI_SETUP_FLAGS()
    # NIUBI_SETUP_SELECT()

    
    SET( OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin )
if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
    SET(OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin64) #64bit
endif( CMAKE_SIZEOF_VOID_P EQUAL 8 )
    SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
    SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")
    SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
    SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")
    SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
    SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")

	IF(BUILD_STATIC_LIBRAY)
		ADD_DEFINITIONS(-DNIUBI_LIBRARY_STATIC)
		ADD_LIBRARY(${NIUBI_SETUP_TARGET_NAME} STATIC ${NIUBI_SETUP_HEADERS} ${NIUBI_SETUP_SOURCES})
	ELSE(BUILD_STATIC_LIBRAY)
		# ADD_DEFINITIONS(-DNIUBI_LIBRARY)
		SET (LIBRARY_TAG  -D${NIUBI_SETUP_TARGET_NAME}_LIBRARY)
		STRING(TOUPPER ${LIBRARY_TAG} LIBRARY_TAG )
		# MESSAGE(${LIBRARY_TAG})
		ADD_DEFINITIONS(${LIBRARY_TAG})
		ADD_LIBRARY(${NIUBI_SETUP_TARGET_NAME} SHARED ${NIUBI_SETUP_HEADERS} ${NIUBI_SETUP_SOURCES})
	ENDIF(BUILD_STATIC_LIBRAY)
	
	SET_TARGET_PROPERTIES(${NIUBI_SETUP_TARGET_NAME} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})

    SET_TARGET_PROPERTIES(${NIUBI_SETUP_TARGET_NAME} PROPERTIES FOLDER "Core")
    
	# TARGET_LINK_LIBRARIES(${NIUBI_SETUP_TARGET_NAME}
		# opengl32 glu32 
		# )

ENDMACRO(NIUBI_SETUP_LIBRARY)

#input NIUBI_SETUP_TARGET_NAME
#input NIUBI_SETUP_SOURCES
#input NIUBI_SETUP_HEADERS
MACRO(NIUBI_SETUP_EXECUTABLE)

    SET(HEADERS_GROUP "Header Files")
    SOURCE_GROUP( ${HEADERS_GROUP} FILES ${NIUBI_SETUP_HEADERS})

    # NIUBI_SETUP_FLAGS()
    # NIUBI_SETUP_SELECT()
    
    SET( OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin )
if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
    SET(OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin64) #64bit
endif( CMAKE_SIZEOF_VOID_P EQUAL 8 )
    SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
    SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")
    SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
    SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")
    SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
    SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")
    
    
	IF(BUILD_STATIC_LIBRAY)
		ADD_DEFINITIONS(-DNIUBI_LIBRARY_STATIC)
	ENDIF(BUILD_STATIC_LIBRAY)
    

    ADD_EXECUTABLE(${NIUBI_SETUP_TARGET_NAME} ${NIUBI_SETUP_HEADERS} ${NIUBI_SETUP_SOURCES})
	
	SET_TARGET_PROPERTIES(${NIUBI_SETUP_TARGET_NAME} PROPERTIES PROJECT_LABEL "${NIUBI_SETUP_TARGET_NAME}")
	SET_TARGET_PROPERTIES(${NIUBI_SETUP_TARGET_NAME} PROPERTIES DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}")
	SET_TARGET_PROPERTIES(${NIUBI_SETUP_TARGET_NAME} PROPERTIES OUTPUT_NAME ${NIUBI_SETUP_TARGET_NAME})
	# SET_TARGET_PROPERTIES(${NIUBI_SETUP_TARGET_NAME} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})


    SET_TARGET_PROPERTIES(${NIUBI_SETUP_TARGET_NAME} PROPERTIES FOLDER "App")
	# TARGET_LINK_LIBRARIES(${NIUBI_SETUP_TARGET_NAME}
		# opengl32 glu32 
        # ${OPENGL_LIBRARIES}
        # ${OPENGL_gl_LIBRARY}
        # /usr/lib/libGL.dll.a
		# ${WOSG_LIBRARY_ALL}
		# ${WOSG_LIBRARY_ALL_PLUGINS}
		# ${WOSG_LIBRARY_ALL_DEPEND}
		# )

ENDMACRO(NIUBI_SETUP_EXECUTABLE)

#input NIUBI_SETUP_TARGET_NAME
#input NIUBI_SETUP_SOURCES
#input NIUBI_SETUP_HEADERS
MACRO(NIUBI_SETUP_PLUGINS)

    SET(HEADERS_GROUP "Header Files")
    SOURCE_GROUP( ${HEADERS_GROUP} FILES ${NIUBI_SETUP_HEADERS})

    # NIUBI_SETUP_FLAGS()
    # NIUBI_SETUP_SELECT()
    
    SET( OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin )
if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
    SET(OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin64) #64bit
endif( CMAKE_SIZEOF_VOID_P EQUAL 8 )
    SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
    SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")
    SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
    SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")
    SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
    SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")
    
	IF(BUILD_STATIC_LIBRAY)
		ADD_DEFINITIONS(-DNIUBI_LIBRARY_STATIC)
		ADD_LIBRARY(${NIUBI_SETUP_TARGET_NAME} STATIC ${NIUBI_SETUP_HEADERS} ${NIUBI_SETUP_SOURCES})
	ELSE(BUILD_STATIC_LIBRAY)
		ADD_DEFINITIONS(-DNIUBI_PULGINS_LIBRARY)
		ADD_LIBRARY(${NIUBI_SETUP_TARGET_NAME} SHARED ${NIUBI_SETUP_HEADERS} ${NIUBI_SETUP_SOURCES})
	ENDIF(BUILD_STATIC_LIBRAY)
	
	SET_TARGET_PROPERTIES(${NIUBI_SETUP_TARGET_NAME} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
    SET_TARGET_PROPERTIES(${NIUBI_SETUP_TARGET_NAME} PROPERTIES FOLDER "Plugins")
	TARGET_LINK_LIBRARIES(${NIUBI_SETUP_TARGET_NAME}
		# opengl32 glu32 
        # ${OPENGL_LIBRARIES}
		# ${WOSG_LIBRARY_ALL}
		# ${WOSG_LIBRARY_ALL_PLUGINS}
		# ${WOSG_LIBRARY_ALL_DEPEND}
		nbPlugins
		)

ENDMACRO(NIUBI_SETUP_PLUGINS)

ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(examples)


